package com.lrsEducation.utils;


import cn.hutool.jwt.JWT;
import cn.hutool.jwt.signers.JWTSignerUtil;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.util.HashMap;
import java.util.Map;

public class loginUtil {

    /**
    * 根据参入参数生成token
    * */
    public static String createToken(String id,String usermobile){
        String token = JWT.create()
                .setPayload("id", id)
                .setPayload("usermobile", usermobile)
                .setSigner(JWTSignerUtil.none())
                .sign();
        return token;
    }
    /*
    * 随机生成六位数
    * */
    public  static  String randomNumber(){
        Integer num =   (int) ((Math.random() * 9 + 1) * 100000);
        return num.toString();
    }
    /*
     * 对密码与言组合生成md5加密文
     * */
    public static Map<String,String> createMd5(String todomd5){
        String passwordPro = loginUtil.randomNumber();
        String ciphertext  = DigestUtils.md5DigestAsHex((todomd5+passwordPro).getBytes(StandardCharsets.UTF_8));
        Map<String,String> data = new HashMap<>();
        data.put("random",passwordPro);
        data.put("password",ciphertext);
        return data;
    }

    public static   String doMd5(String todo){
        String ciphertext  = DigestUtils.md5DigestAsHex((todo).getBytes(StandardCharsets.UTF_8));
        return ciphertext;
    }

}
